package com.lj.eduservice.controller;


import com.lj.eduservice.entity.Video;
import com.lj.eduservice.entity.dao.VideoDao;
import com.lj.eduservice.service.VideoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2021-05-06
 */
@RestController
@RequestMapping("/eduservice/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation("添加或更新小节")
    @PostMapping("/addOrUpdateVideo")
    public Boolean addOrUpdateVideo(@RequestBody VideoDao videoDao){
        Video video = new Video();
        BeanUtils.copyProperties(videoDao,video);
        return videoService.saveOrUpdate(video);
    }

    /**
     * @param videoId
     * @return
     */
    @ApiOperation("根据小节id删除小节")
    @DeleteMapping("/deleteVideo/{videoId}")
    public Boolean deleteVideo(@PathVariable("videoId") String videoId){
        return videoService.deleteVideo(videoService.getById(videoId));
    }
}

